<?php

// +---------------------------------------------+
// |     Copyright  2010 - 2018 InterPhoto       |
// |     http://www.weentech.com                 |
// |     This file may not be redistributed.     |
// +---------------------------------------------+

include('includes/Admin.Core.php');

CheckAccess('manageimage');


PrintHeader('管理图片');

$action = ForceIncomingString('action', 'displayimages');
if(IsPost('updateimages')) $action= 'updateimages';
if(IsPost('deleteimages')) $action= 'deleteimages';

@set_time_limit(0);

// ############################## FUNCTIONS #############################

function CreateDirectory($path) {
	if (!file_exists($path)) {
		mkdir($path, 0777);
		@chmod($path, 0777);
	}
}

function GetSearchSql($search, $categoryid) {
	$sWhere = '';
	if($search != ''){
		$sWhere .= " WHERE (username LIKE '%".$search."%' OR price LIKE '%".$search."%' OR title LIKE '%".$search."%' OR description LIKE '%".$search."%' OR keywords LIKE '%".$search."%') ";

		if($categoryid > 0){
			$sWhere .= " AND categoryid = '$categoryid' ";
		}elseif($categoryid == '-1'){
			$sWhere .= " AND actived = '0' ";
		}
	}elseif($categoryid > 0){
		$sWhere .= " WHERE categoryid = '$categoryid' ";
	}elseif($categoryid == '-1' ){
		$sWhere .= " WHERE actived = '0' ";
	}

	return $sWhere;
}

function UploadImage($imagefile, $uploaddir, $file_path, $imagename) {
	CreateDirectory($uploaddir.$file_path);
	CreateDirectory($uploaddir.$file_path.'/32x32/');
	CreateDirectory($uploaddir.$file_path.'/80x80/');
	CreateDirectory($uploaddir.$file_path.'/160x160/');
	CreateDirectory($uploaddir.$file_path.'/760x760/');
	CreateDirectory($uploaddir.$file_path.'/original/');

	if((function_exists('move_uploaded_file') AND @move_uploaded_file($imagefile['tmp_name'], $uploaddir.$file_path.'/'.$imagename)) OR @rename($imagefile['tmp_name'], $uploaddir.$file_path.'/'.$imagename))	{

		$image_size = @getimagesize($uploaddir.$file_path.'/'.$imagename);

		if ($image_size[0] > 760 || $image_size[1] > 760) {
			if (@rename($uploaddir.$file_path.'/'.$imagename, $uploaddir.$file_path.'/original/'.$imagename)) {
				CreateImageFile($uploaddir.$file_path.'/original/'.$imagename, $uploaddir.$file_path."/760x760/".$imagename,'760');
				CreateImageFile($uploaddir.$file_path.'/760x760/'.$imagename, $uploaddir.$file_path."/160x160/".$imagename,'160');
				CreateImageFile($uploaddir.$file_path.'/160x160/'.$imagename, $uploaddir.$file_path."/80x80/".$imagename,'80');
				CreateImageFile($uploaddir.$file_path.'/80x80/'.$imagename, $uploaddir.$file_path."/32x32/".$imagename,'32');
			}
		}else{
			if (@rename($uploaddir.$file_path.'/'.$imagename, $uploaddir.$file_path.'/760x760/'.$imagename)) {
				CreateImageFile($uploaddir.$file_path.'/760x760/'.$imagename, $uploaddir.$file_path."/160x160/".$imagename,'160');
				CreateImageFile($uploaddir.$file_path.'/160x160/'.$imagename, $uploaddir.$file_path."/80x80/".$imagename,'80');
				CreateImageFile($uploaddir.$file_path.'/80x80/'.$imagename, $uploaddir.$file_path."/32x32/".$imagename,'32');
			}
		}

		return true;

	}else{
		return false;
	}
}

function CreateImageFile($src_path, $des_path, $new_dims) {
	$source = @imagecreatefromjpeg($src_path);

	if ($source) {
		$imageX = @imagesx($source);
		$imageY = @imagesy($source);
		
		if ($imageX >= $imageY) {
			if($imageX >= $new_dims){
				$thumbX = $new_dims;
				$thumbY = (int)(($thumbX*$imageY) / $imageX );
			}else{
				$thumbX = $imageX;
				$thumbY = $imageY;
			}
		} else {
			if($imageY >= $new_dims){
				$thumbY = $new_dims;
				$thumbX = (int)(($thumbY*$imageX) / $imageY );
			}else{
				$thumbX = $imageX;
				$thumbY = $imageY;
			}
		}

		$dest_thum  = @imagecreatetruecolor($thumbX, $thumbY);
		@imagecopyresampled ($dest_thum, $source, 0, 0, 0, 0, $thumbX, $thumbY, $imageX, $imageY);
		@imageinterlace($dest_thum);
		@imagejpeg($dest_thum,$des_path,85);
		@ImageDestroy($dest_thum);
		@ImageDestroy($source);
	}
}


function GetCategorySelect($selectname, $selectedid = 0){
	$sReturn = '<select name="' . $selectname . '">';
	$sReturn .= GetOptions($selectedid);
	$sReturn .= '</select>';

	return $sReturn;
}

function GetOptions($selectedid = 0, $parentid = 0, $sublevelmarker = ''){
	global $icategories;

	if($parentid) $sublevelmarker .= '&minus;&minus;';

	$allicategories = $icategories;
	foreach($allicategories as $value){
		if($parentid == $value['parentid']){
			$sReturn .= '<option value="' . $value['categoryid'] . '" ' . Iif($selectedid == $value['categoryid'], 'SELECTED', '') . '>' . $sublevelmarker . ShortTitle($value['title'], 18) . '</option>';

			$sReturn .= GetOptions($selectedid, $value['categoryid'], $sublevelmarker);
		}
	}

	return $sReturn;
}


// ################################ INSERT IMAGE ################################

if($action == 'insertimage' OR $action == 'updateimage')
{
	$imageid     = ForceIncomingInt('imageid');
	$ordernum     = ForceIncomingInt('ordernum');
	$categoryid     = ForceIncomingInt('categoryid');
	$usergroup        = ForceIncomingString('usergroup');
	$usergroupids     = ForceIncomingArray('usergroupids');
	$username        = ForceIncomingString('username');
	$title        = ForceIncomingString('title');
	$description        = ForceIncomingString('description');
	$keywords        = ForceIncomingString('keywords');
	$url        = ForceIncomingString('url');
	$viewcount     = ForceIncomingInt('viewcount');
	$downloadcount     = ForceIncomingInt('downloadcount');
	$sale     = ForceIncomingInt('sale');
	$price        = ForceIncomingString('price');
	$watermark     = ForceIncomingInt('watermark');
	$actived     = ForceIncomingInt('actived');
	$deletethisimage     = ForceIncomingInt('deletethisimage');

	if($usergroup == 'all' OR count($usergroupids) < 1){
		$usergroupids = 'all';
	}else{
		$usergroupids = '('.implode(');(', $usergroupids).')';
	}

	if ($action == 'insertimage')
	{
		$imagefile         = $_FILES['imagefile'];

		if(strlen($username) == 0){
			$username = $userinfo['username'];
		}

		$valid_image_types = array('image/pjpeg',	'image/jpeg', 'image/jpg');

		$uploaddir = BASEPATH.'MyWebsiteImages/';
		@chmod($uploaddir,0777);

		if (!$categoryid)
		{
			$errors[] ='上传图片前请先添加图片分类目录!';
		}

		if (!function_exists('imagecreatetruecolor'))
		{
			$errors[] ='服务器PHP环境不支持GD2库, 无法上传图片文件!';
		}

		if (!is_dir($uploaddir)){
			$errors[] ='保存图片的文件夹: MyWebsiteImages/ 不存在!';
		}else if (!is_writable($uploaddir)){
			$errors[] = '保存图片的文件夹: MyWebsiteImages/ 不可写! - 文件夹属性需改为: 0777';
		}

		if($imagefile['size'] == 0)	{
			$errors[] = '未选择图片文件, 或文件大小超过了服务器PHP环境允许上传的文件大小: '.ini_get('upload_max_filesize');
		}elseif (!IsUploadedFile($imagefile['tmp_name']) || !($imagefile['tmp_name'] != 'none' && $imagefile['tmp_name'] && $imagefile['name']) ){
			$errors[] ='Possible file upload attack!';
		}elseif(!in_array($imagefile['type'], $valid_image_types)){
			$errors[] = '无效的图片文件类型!';
		}else{
			$filesizelimit = $DB->query_first("SELECT title, datasize FROM " . TABLE_PREFIX . "categories WHERE categoryid = '$categoryid' ");
			if($imagefile['size'] > $filesizelimit['datasize'] *1024){
				$errors[] = '文件大小超过图片目录('.$filesizelimit['title'].')限制的大小: '. DisplayFilesize($filesizelimit['datasize'] *1024);
			}
		}

		if(!isset($errors))
		{
			$file_path_name = DisplayDate(time(), 'Y_m');
			$filepieces = explode('.', basename($imagefile['name']));
			$fileExtension = strtolower($filepieces[count($filepieces)-1]);
			$imagename = md5(uniqid(COOKIE_KEY.time())).'.'.$fileExtension;
			$file_path = $file_path_name.'_'.WEBSITE_KEY;

			if(UploadImage($imagefile, $uploaddir, $file_path, $imagename)){

				$DB->query("INSERT INTO " . TABLE_PREFIX . "images VALUES (NULL, '$ordernum',  '$categoryid', '$userinfo[userid]', '$username', '$actived', '$watermark', '$sale', 0, '$usergroupids', '$file_path_name', '$imagename', '$price', '$title', '$description', '', '$keywords', '$url', '0', '0', '".time()."')");

				$imageid = $DB->insert_id();
				$DB->query("UPDATE " . TABLE_PREFIX . "images SET ordernum = '$imageid' WHERE imageid = '$imageid'");

				PrintRedirect('admin.images.php', 1);
			}else{
				$errors ='上传文件失败!';
			}
		}

		PrintErrors($errors, '添加图片错误');
		$action = 'addimage';

	}elseif($action == 'updateimage'){
		if($deletethisimage){
			DeleteImageById ($imageid);
			PrintRedirect('admin.images.php', 1);
		}

		$DB->query("UPDATE " . TABLE_PREFIX . "images SET 
		ordernum     = '$ordernum',
		categoryid = '$categoryid',
		".Iif($username, "username = '$username',") . "
		actived     = '$actived',
		watermark     = '$watermark',
		sale     = '$sale',
		usergroupids     = '$usergroupids',
		price     = '$price',
		title     = '$title',
		description     = '$description',
		keywords     = '$keywords',
		url     = '$url',
		viewcount     = '$viewcount',
		downloadcount     = '$downloadcount'
		WHERE imageid   = '$imageid'");

		PrintRedirect('admin.images.php', 1);
	}

}


// ############################### UPDATE IMAGES ################################


if($action == 'updateimages'){
	$imageids   = ForceIncomingArray('updateimageids');
	$ordernums   = ForceIncomingArray('ordernums');
	$activeds   = ForceIncomingArray('activeds');
	$titles   = ForceIncomingArray('titles');
	$categoryids   = ForceIncomingArray('categoryids');

    for($i = 0; $i < count($imageids); $i++)
    {
		$DB->query("UPDATE " . TABLE_PREFIX . "images SET ordernum = '". ForceInt($ordernums[$i])."',
		actived = '$activeds[$i]',
		categoryid = '$categoryids[$i]',
		title = '$titles[$i]'
		WHERE imageid = '$imageids[$i]'");
    }

    PrintRedirect('admin.images.php', 1);

}


// ############################### DELETE IMAGES ################################

if($action == 'deleteimages')
{
	$deleteimageids = ForceIncomingArray('deleteimageids');

	for($i = 0; $i < count($deleteimageids); $i++){
		DeleteImageById (ForceInt($deleteimageids[$i]));
	}

	PrintRedirect('admin.images.php', 1);
}

// ############################ DISPLAY IMAGE FORUM #############################

if($action == 'addimage' OR $action == 'editimage')
{
	$getcategories = $DB->query("SELECT categoryid, parentid, title  FROM " . TABLE_PREFIX . "categories ORDER BY ordernum");
	$icategories = $DB->getrows($getcategories);

	$imageid = ForceIncomingInt('imageid');

	if(isset($errors))
	{
		// new image or edit image with errors, redisplaying the form
		$image = array('imageid'   => $imageid,
			  'categoryid'  => $categoryid,
			  'usergroup'     => $usergroup,
			  'usergroupids'     => $usergroupids,
			  'username'     => $username,
			  'title'     => $title,
			  'description'     => $_POST['description'],
			  'keywords'     => $keywords,
			  'url'     => $url,
			  'sale'     => $sale,
			  'price'     => $price,
			  'watermark'     => $watermark,
			  'actived'     => $actived);

	} else if($imageid) {
		$image = $DB->query_first("SELECT * FROM " . TABLE_PREFIX . "images WHERE imageid = '$imageid'");
	}else{
		$image = array('imageid' => 0, 'categoryid' => 0, 'actived' => 1,  'watermark' => 1,  'usergroupids' => 'all');
	}

	if($imageid)
	{
		PrintSection('编辑图片: ' . Iif($image['title'], ShortTitle($image['title'], 36), '无标题图片'));
	}else{
		PrintSection('添加图片');
	}

	$getusergroups = $DB->query("SELECT groupid, name FROM " . TABLE_PREFIX . "usergroups ORDER BY groupid");
	while($usergroup = $DB->getrow($getusergroups)) {
		$usergroups[$usergroup['groupid']] = $usergroup['name'];
	}

	echo '<script src="'.BASEURL.'library/editor/nicEdit.js" type="text/javascript"></script>
	<script type="text/javascript">
	bkLib.onDomLoaded(function() {
		new nicEditor({fullPanel:true, iconsPath: \''.BASEURL.'library/editor/nicEditorIcons.gif\', maxHeight:170}).panelInstance("description");
	});
	</script>';

	echo '<form enctype="multipart/form-data" method="post" action="admin.images.php">
	<input type="hidden" name="action" value="' . Iif($imageid, 'updateimage', 'insertimage') . '" />
	<input type="hidden" name="imageid" value="' . $image['imageid'] . '" />
	<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
	<td class="tdrow2" nowrap="nowrap"><b>' . Iif($imageid, Iif($image['actived'] == 1, '浏览图片', '<font class=ohred>待审图片</font>'), '上传图片') . ':</b></td>
	<td class="tdrow3">' . Iif($imageid, Iif($image['actived'] == 1, '<a href="'.BASEURL.'InterPhoto.php?id='.$image['imageid'].'" target="_blank">') . '<img src="admin.thumbnail.php?file='.InterEncode($image['path'].'/1/'.$image['filename']).'" border="0" onMouseMove="ShowBigImage();" />'. Iif($image['actived'] == 1, '</a>'), '<input name="imagefile" type="file" size="38" />&nbsp;&nbsp;(注: 仅允许上传<font class=ohredb>JPG</font>类型的图片文件)') . '</td>
	</tr>';

	if($imageid)
	{
		echo '<tr>
		<td class="tdrow2" nowrap="nowrap"><b>是否删除:</b></td>
		<td class="tdrow3"><input type="checkbox" name="deletethisimage" value="1"> <b>是:</b> <font class=ohredb>慎选!</font> 如果选择删除, 此图片相关的信息, 缩图, 评论等将全部被删除.</td>
		</tr>
		<tr>
		<td class="tdrow2" nowrap="nowrap"><b>编号:</b></td>
		<td class="tdrow3"><input type="text" name="ordernum" value="'.$image['ordernum'].'" size="16" /></td>
		</tr>';
	}

	echo '<tr>
	<td class="tdrow2" nowrap="nowrap"><b>所属目录:</b></td>
	<td class="tdrow3">'.GetCategorySelect('categoryid',$image['categoryid']).'</td>
	</tr>
	<tr>
	<td class="tdrow2" nowrap="nowrap"><b>可见用户组:</b></td>
	<td class="tdrow3"><input type="radio" name="usergroup" value="all" '.Iif($image['usergroupids'] == 'all', ' checked="checked"').' onclick="HideDIV(\'div_usergroupids\');">所有用户组&nbsp;&nbsp;&nbsp;<input type="radio" name="usergroup" value="none" '.Iif($image['usergroupids'] != 'all', ' checked="checked"').' onclick="ShowDIV(\'div_usergroupids\');">选择用户组 (注: 指此图片对于哪些用户组可见)<BR><div id="div_usergroupids" style="border: 1px solid #996600;background-color:#fffeec;margin:6px;padding:6px; display: '.Iif($image['usergroupids'] != 'all', 'block', 'none').';">';

	foreach($usergroups as $key => $value)
	{
		echo '<input  type="checkbox" name="usergroupids[]" value="' . $key . '" ' . Iif(preg_match('/('.$key.')/i', $image['usergroupids']), ' CHECKED') . '>' . $value . '&nbsp;&nbsp;&nbsp;&nbsp;';
	}

	echo '</div>
	</td>
	</tr>
	<tr>
	<td class="tdrow2" nowrap="nowrap"><b>发布人:</b></td>
	<td class="tdrow3">';

	if($image['userid'] ==$userinfo['userid'])
	{
		echo '<input type="text" name="username" value="'.$image['username'].'" size="16" />';
	}else if ($imageid){
		if($image['userid']){
			echo '<a href="admin.users.php?action=edituser&userid='.$image['userid'].'">' . Iif(strlen($image['username']), $image['username'], '无名'). '</a>';
		}else{
			echo Iif(strlen($image['username']), '<font color="#B6B6B6">'.$image['username'].'</font>', '无名');
		}
	}else{
		echo '<input type="text" name="username" value="'.$userinfo['username'].'" size="16" />';
	}

	echo '</td>
	</tr>
	<tr>
	<td class="tdrow2" nowrap="nowrap"><b>图片标题:</b></td>
	<td class="tdrow3"><input type="text" name="title" value="'.$image['title'].'" size="40" /></td>
	</tr>
	<tr>
	<td class="tdrow2" nowrap="nowrap"><b>图片说明:</b></td>
	<td class="tdrow3" style="background: #fff;"><textarea name="description" style="height:160px;width:600px;" id="description">'.$image['description'].'</textarea></td>
	</tr>	
	<tr>
	<td class="tdrow2" nowrap="nowrap"><b>Meta关键字:</b></td>
	<td class="tdrow3"><input type="text" name="keywords" value="'.$image['keywords'].'" size="60" /></td>
	</tr>
	<tr>
	<td class="tdrow2" nowrap="nowrap"><b>图片链接URL:</b></td>
	<td class="tdrow3"><input type="text" name="url" value="'.$image['url'].'" size="60" /></td>
	</tr>';

	if($imageid)
	{
		echo '<tr>
		<td class="tdrow2" nowrap="nowrap"><b>点击次数:</b></td>
		<td class="tdrow3"><input type="text" name="viewcount" value="'.$image['viewcount'].'" size="16" /></td>
		</tr>
		<tr>
		<td class="tdrow2" nowrap="nowrap"><b>下载次数:</b></td>
		<td class="tdrow3"><input type="text" name="downloadcount" value="'.$image['downloadcount'].'" size="16" /></td>
		</tr>';
	}

	echo '
	<tr>
	<td class="tdrow2" nowrap="nowrap"><b>用于销售:</b></td>
	<td class="tdrow3"><input type="checkbox" name="sale" value="1" '.Iif($image['sale'] == 1, 'CHECKED').'> <b>是:</b> 当选择用于销售时, 此图片将显示其价格, 自动添加大图水印而且不允许任何用户组下载.</td>
	</tr>
	<tr>
	<td class="tdrow2" nowrap="nowrap"><b>图片价格:</b></td>
	<td class="tdrow3"><input type="text" name="price" value="'.$image['price'].'" size="16" /></td>
	</tr>
	<tr>
	<td class="tdrow2" nowrap="nowrap"><b>添加水印:</b></td>
	<td class="tdrow3"><input type="checkbox" name="watermark" value="1" '.Iif($image['watermark'] == 1, 'CHECKED').'> <b>是:</b> 是否在显示大图时自动添加水印?</td>
	</tr>
	<tr>
	<td class="tdrow2" nowrap="nowrap"><b>是否发布:</b></td>
	<td class="tdrow3"><input type="checkbox" name="actived" value="1" '.Iif($image['actived'] == 1, 'CHECKED').'> <b>是:</b> 是否发布此图片?</td>
	</tr>';

		
	echo '<tr>
	<td class="tdrow1" bgcolor="#FCFCFC" colspan="2" align="center">
	<input type="submit" value="' . Iif($imageid, '保存更新', '提交保存') . '" />
	</td>
	</tr>
	</table>
	</form>';

	EndSection();
}


// ############################### DISPLAY IMAGES ###############################

if($action == 'displayimages')
{
	$getcategories = $DB->query("SELECT categoryid, parentid, title  FROM " . TABLE_PREFIX . "categories ORDER BY ordernum");
	$icategories = $DB->getrows($getcategories);

	$NumPerPage =20;

	$page = ForceIncomingInt('page', 1);
	$search = ForceIncomingString('s');
	$categoryid = ForceIncomingInt('c');

	if(IsGet('s')){
		$search = urldecode($search);
	}

	$start = $NumPerPage * ($page-1);

	PrintSection('上传图片');
	echo '<form method="post" action="admin.images.php">
	<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
	<td class="tdrow3" align="center">
	<input type="hidden" name="action" value="addimage" />
	<input type="submit" value=" 单个上传 " />&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" onclick="location.href=\'admin.ftpimages.php\'" value=" 批量上传 " /></td>
	</tr>
	</table></form>';
	EndSection();

	PrintSection('搜索图片');
	echo '<form method="post" action="admin.images.php" name="searchimages">
	<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
	<td class="tdrow2" align="center">搜索:&nbsp;<input type="text" name="s" size="22">&nbsp;&nbsp;目录:&nbsp;<select name="c"><option value="0">全部分类目录</option><option style="color:red;" value="-1">未发布的图片</option>' . GetOptions() . '</select>&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="searchimage" value="搜索图片" /></td>
	</tr>
	</table></form>';
	EndSection();

	$title = Iif(IsPost('searchimage'), '搜索到的图片列表', '全部图片列表');

	$getimages = $DB->query("SELECT imageid, ordernum, categoryid, userid, username, actived, path, filename, title, viewcount, downloadcount, created FROM " . TABLE_PREFIX . "images ".GetSearchSql($search, $categoryid)." ORDER BY actived ASC, ordernum DESC LIMIT $start,$NumPerPage");

	$maxrows = $DB->query_first("SELECT COUNT(imageid) AS value FROM " . TABLE_PREFIX . "images ".GetSearchSql($search, $categoryid));

	PrintSection($title.'('.$maxrows['value'].'个)');

	echo '<form method="post" action="admin.images.php" name="imagesform">
	<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
	<td class="tdrow1" nowrap="nowrap">编号</td>
	<td class="tdrow1" nowrap="nowrap">缩图</td>
	<td class="tdrow1" nowrap="nowrap">标题</td>
	<td class="tdrow1" nowrap="nowrap">用户</td>
	<td class="tdrow1" nowrap="nowrap">状态</td>
	<td class="tdrow1" nowrap="nowrap">目录</td>
	<td class="tdrow1" nowrap="nowrap">点击</td>
	<td class="tdrow1" nowrap="nowrap">下载</td>
	<td class="tdrow1" nowrap="nowrap">日期</td>
	<td class="tdrow1" nowrap="nowrap"><input type="checkbox" checkall="group" onclick="javascript: return select_deselectAll (\'imagesform\', this, \'group\');"> 删除</td>
	</tr>';

	if($maxrows['value'] < 1){
		echo '<tr><td class="tdrow3" colspan="10" align="center" height="48" valign="middle"><font class=ohredb>未搜索到任何图片!</font></td></tr>';
	}else{
		while($image = $DB->getrow($getimages))
		{
			echo '<tr>
			<td class="tdrow2"><input type="hidden" name="updateimageids[]" value="'.$image['imageid'].'" /><input type="text" name="ordernums[]" value="' . $image['ordernum'] . '" size="4" /></td>
			<td class="tdrow3"><a href="admin.images.php?action=editimage&imageid='.$image['imageid'].'"><img src="admin.thumbnail.php?file='.InterEncode($image['path'].'/0/'.$image['filename']).'" border="0" onMouseMove="ShowBigImage();" /></a></td>
			<td class="tdrow2"><input type="text" name="titles[]" value="' . $image['title'] . '" size="16" /></td>
			<td class="tdrow3">';
			
			if($image['userid']){
				echo '<a href="admin.users.php?action=edituser&userid='.$image['userid'].'">' . Iif(strlen($image['username']), $image['username'], '无名'). '</a>';
			}else{
				echo Iif(strlen($image['username']), '<font color="#B6B6B6">'.$image['username'].'</font>', '无名');
			}
				
			echo '</td>
			<td class="tdrow2"><select name="activeds[]">
			<option value="1">发布</option>
			<option style="color:red;" value="0" ' . Iif(!$image['actived'], 'SELECTED', '') . '>待审</option>
			</select></td>
			<td class="tdrow3">' . GetCategorySelect('categoryids[]', $image['categoryid']) . '</td>
			<td class="tdrow2">' . $image['viewcount'] . '</td>
			<td class="tdrow3">' . $image['downloadcount'] . '</td>
			<td class="tdrow2">' . DisplayDate($image['created'], 'Y-m-d') . '</td>
			<td class="tdrow3"><input type="checkbox" name="deleteimageids[]" value="' . $image['imageid'] . '" checkme="group" /></td>
			</tr>';
		}
	}

	$totalpages = ceil($maxrows['value'] / $NumPerPage);

	if($totalpages > 1){
		echo '<tr><td class="tdrow3" colspan="10" align="center" height="48" valign="middle">';
		echo GetPageList('admin.images.php', $totalpages, $page, 10, 's', urlencode($search), 'c', $categoryid);
		echo '</td></tr>';
	}

	if($maxrows['value'] > 0){
		echo '<tr><td class="tdrow1" colspan="10" align="center"><input type="submit" name="updateimages" value=" 保存更新 " />&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="deleteimages" onclick="return confirm(\'确定删除所选图片吗?\');" value=" 删除图片 " /></td></tr>';
	}

	echo '</table></form>';

	EndSection();
}


// ############################### PRINT FOOTER ################################

PrintFooter();

?>